package com.goldcn.picture.controller;

import com.goldcn.interceptor.SystemContext;
import com.goldcn.picture.dto.QueryPicInfoDto;
import com.goldcn.picture.dto.QueryPicTagDto;
import com.goldcn.picture.service.*;
import com.goldcn.picture.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/picture")
@Api(value = "图库中心", description = "图库中心微服务")
public class PictureController {

    @Autowired
    PicLabelService picLabelService;

    @Autowired
    PicSpecialService picSpecialService;

    @Autowired
    PicStorageService picStorageService;

    @Autowired
    PictureService pictureService;

    @Autowired
    PicTagsService picTagsService;

    @Autowired
    PicDictService picDictService;

    @Autowired
    PicSeriesService picSeriesService;


    @Autowired
    RedisTemplate redisTemplate;


    @ApiOperation(value = "新增图片标签")
    @RequestMapping(value = "/picLabel",method = RequestMethod.POST)
    public Object addPicLabel(@RequestBody PicLabelVo picLabelVo){
        return picLabelService.addPicLabel(picLabelVo);
    }

    @ApiOperation(value = "删除图片标签")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "labelID", required = true, value = "标签的labelID", defaultValue = "X123"),
    })
    @RequestMapping(value = "/picLabel/{labelID}", method = RequestMethod.DELETE)
    public Object delLabel(@PathVariable Long labelID) {
        return picLabelService.deleteByPrimaryKey(labelID);
    }


    @ApiOperation(value = "修改标签信息")
    @RequestMapping(value = "/picLabel", method = RequestMethod.PUT)
    public Object updatePicLabel(@RequestBody PicLabelVo picLabelVo) {
        return picLabelService.updateByPicLabel(picLabelVo);
    }

    @ApiOperation(value = "标签ID删除当下所属图片")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "labelID", required = true, value = "标签的labelID", defaultValue = "X123"),
    })
    @RequestMapping(value = "/picLabel/del/{labelID}", method = RequestMethod.DELETE)
    public Object deletePicByLabelId(@PathVariable Long labelID) {
        return picLabelService.deletePicByLabelId(labelID);
    }


    @ApiOperation(value = "查询图片标签")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "labelID", required = true, value = "标签的labelID", defaultValue = "a123"),
    })
    @RequestMapping(value = "/picLabel/{labelID}", method = RequestMethod.GET)
    public Object getByLabel(@PathVariable Long labelID) {
        return picLabelService.selectByPrimaryKey(labelID);
    }



    @ApiOperation(value = "图片ID查询标签列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "pageSize", required = true, value = "分页大小", defaultValue = "5"),
            @ApiImplicitParam(paramType = "path", name = "pageNum", required = true, value = "当前页", defaultValue = "1"),
    })
    @RequestMapping(value = "/picLabel/list/{pictureID}/{pageNum}/{pageSize}", method = RequestMethod.GET)
    public Object getPicLableList(@PathVariable Long pictureID,@PathVariable Integer pageNum,@PathVariable Integer pageSize) {
        return picLabelService.getPicLableList(pictureID,pageNum,pageSize);
    }

    @ApiOperation(value = "标签ID查询图片列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "pageSize", required = true, value = "分页大小", defaultValue = "5"),
            @ApiImplicitParam(paramType = "path", name = "pageNum", required = true, value = "当前页", defaultValue = "1"),
    })
    @RequestMapping(value = "/picLabel/listPic/{labelid}/{pageNum}/{pageSize}", method = RequestMethod.GET)
    public Object queryPicInfoBylabelId(@PathVariable Long labelid,@PathVariable Integer pageNum,@PathVariable Integer pageSize) {
        return picLabelService.queryPicInfoBylabelId(labelid,pageNum,pageSize);
    }

    @ApiOperation(value = "用户ID查询标签列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "pageSize", required = true, value = "分页大小", defaultValue = "5"),
            @ApiImplicitParam(paramType = "path", name = "pageNum", required = true, value = "当前页", defaultValue = "1"),
    })
    @RequestMapping(value = "/picLabel/listV2/{pictureID}/{pageNum}/{pageSize}", method = RequestMethod.GET)
    public Object getUserPicLableList(@PathVariable Long pictureID,@PathVariable Integer pageNum,@PathVariable Integer pageSize) {
        return picLabelService.getUserPicLableList(pictureID,pageNum,pageSize);
    }

    @ApiOperation(value = "批量删除标签所属图片")
    @RequestMapping(value = "/picLabel/del", method = RequestMethod.POST)
    public Object delPicLabelDetail(@RequestBody List<String> detailIds) {
        return picLabelService.delPicLabelDetail(detailIds);
    }

    @ApiOperation(value = "批量添加标签所属图片")
    @RequestMapping(value = "/picLabelDetail", method = RequestMethod.POST)
    public Object addPicLabelDetail(@RequestBody PicLabelDetailVo picLabelDetailVo) {
        return picLabelService.addPicLabelDetail(picLabelDetailVo);
    }


    @ApiOperation(value = "新增专题")
    @RequestMapping(value = "/picSpecial",method = RequestMethod.POST)
    public Object addPicSpecial(@RequestBody PicSpecialVo picSpecialVo){return picSpecialService.addPicSpecial(picSpecialVo);
    }

    @ApiOperation(value = "删除专题")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "specialID", required = true, value = "专题的specialID", defaultValue = "X123"),
    })
    @RequestMapping(value = "/picSpecial/{specialID}", method = RequestMethod.DELETE)
    public Object deleteByPrimaryKey(@PathVariable Long specialID) {
        return picSpecialService.deleteByPrimaryKey(specialID);
    }


    @ApiOperation(value = "修改专题")
    @RequestMapping(value = "/picSpecial", method = RequestMethod.PUT)
    public Object updatePicSpecial(@RequestBody PicSpecialVo picSpecialVo) {
        return picSpecialService.updateByPicSpecial(picSpecialVo);
    }

    @ApiOperation(value = "根据专题ID删除当下所属图片")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "specialID", required = true, value = "专题的specialID", defaultValue = "X123"),
    })
    @RequestMapping(value = "/picSpecial/del/{specialID}", method = RequestMethod.DELETE)
    public Object deletePicBySpecialId(@PathVariable Long specialID) {
        return picSpecialService.deletePicBySpecialId(specialID);
    }

    @ApiOperation(value = "批量删除专题所属图片")
    @RequestMapping(value = "/picSpecial/del", method = RequestMethod.POST)
    public Object deletePicBySpecialDetail(@RequestBody List<String> detailIds) {
        return picSpecialService.delPicSpecialDetail(detailIds);
    }

    @ApiOperation(value = "批量添加专题图片")
    @RequestMapping(value = "/picSpecialDetail", method = RequestMethod.POST)
    public Object addPicBySpecialDetail(@RequestBody PicSpecialDetailVo picSpecialVo) {
        return picSpecialService.addPicSpecialDetail(picSpecialVo);
    }

    @ApiOperation(value = "查询专题")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "specialID", required = true, value = "专题的specialID", defaultValue = "a123"),
    })
    @RequestMapping(value = "/picSpecial/{specialID}", method = RequestMethod.GET)
    public Object getBySpecial(@PathVariable Long specialID) {
        return picSpecialService.selectByPrimaryKey(specialID);
    }

    @ApiOperation(value = "图片ID查询专题列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "pageSize", required = true, value = "分页大小", defaultValue = "5"),
            @ApiImplicitParam(paramType = "path", name = "pageNum", required = true, value = "当前页", defaultValue = "1"),
    })
    @RequestMapping(value = "/picSpecial/list/{pictureID}/{pageNum}/{pageSize}", method = RequestMethod.GET)
    public Object selectListByPictureId(@PathVariable Long pictureID,@PathVariable Integer pageNum,@PathVariable Integer pageSize) {
        return picSpecialService.selectListByPictureId(pictureID,pageNum,pageSize);
    }


    @ApiOperation(value = "用户ID查询专题列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "pageSize", required = true, value = "分页大小", defaultValue = "5"),
            @ApiImplicitParam(paramType = "path", name = "pageNum", required = true, value = "当前页", defaultValue = "1"),
    })
    @RequestMapping(value = "/picSpecial/listV2/{userID}/{pageNum}/{pageSize}", method = RequestMethod.GET)
    public Object selectListByUserId(@PathVariable Long userID,@PathVariable Integer pageNum,@PathVariable Integer pageSize) {
        return picSpecialService.selectListByUserId(userID,pageNum,pageSize);
    }

    @ApiOperation(value = "专题ID查询图片列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "pageSize", required = true, value = "分页大小", defaultValue = "5"),
            @ApiImplicitParam(paramType = "path", name = "pageNum", required = true, value = "当前页", defaultValue = "1"),
    })
    @RequestMapping(value = "/picSpecial/listPic/{specialID}/{pageNum}/{pageSize}", method = RequestMethod.GET)
    public Object selectListPicBySpecialId(@PathVariable Long specialID,@PathVariable Integer pageNum,@PathVariable Integer pageSize) {
        return picSpecialService.selectListPicBySpecialId(specialID,pageNum,pageSize);
    }

    @ApiOperation(value = "用户ID查询出入库")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "pageSize", required = true, value = "分页大小", defaultValue = "5"),
            @ApiImplicitParam(paramType = "path", name = "pageNum", required = true, value = "当前页", defaultValue = "1"),
    })
    @RequestMapping(value = "/picStorage/list/{pageNum}/{pageSize}", method = RequestMethod.POST)
    public Object getStorageListByUserId(@RequestBody StorageByUserVo storageByUserVo,@PathVariable Integer pageNum,@PathVariable Integer pageSize) {
        return picStorageService.selectListByUserId(storageByUserVo,pageNum,pageSize);
    }

    @ApiOperation(value = "新增出入库")
    @RequestMapping(value = "/picStorage",method = RequestMethod.POST)
    public Object addPicStorage(@RequestBody PicStorageVo picStorageVo){
        return picStorageService.addPicStorage(picStorageVo);
    }

    @ApiOperation(value = "删除出入库")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "storageID", required = true, value = "出入库storageID", defaultValue = "X123"),
    })
    @RequestMapping(value = "/picStorage/{storageID}", method = RequestMethod.DELETE)
    public Object deleteStorag(@PathVariable Long storageID) {
        return picStorageService.deleteByPrimaryKey(storageID);
    }


    @ApiOperation(value = "查询出入库")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "storageID", required = true, value = "出入库storageID", defaultValue = "a123"),
    })
    @RequestMapping(value = "/picStorage/{storageID}", method = RequestMethod.GET)
    public Object getByPicStorag(@PathVariable Long storageID) {
        return picStorageService.selectByPrimaryKey(storageID);
    }

    @ApiOperation(value = "修改出入库")
    @RequestMapping(value = "/picStorage", method = RequestMethod.PUT)
    public Object updatePicStorag(@RequestBody PicStorageVo picStorageVo) {
        return picStorageService.updateByPicStorage(picStorageVo);
    }

    @ApiOperation(value = "审核出入库")
    @RequestMapping(value = "/picStorage/audit", method = RequestMethod.POST)
    public Object auditStorage(@RequestBody PicAuditVo picAuditVo) {
        return picStorageService.auditStorage(picAuditVo);
    }

    @ApiOperation(value = "审核图片")
    @RequestMapping(value = "/picInfo/audit", method = RequestMethod.POST)
    public Object auditPicInfo(@RequestBody PicAuditVo picAuditVo) {
        return pictureService.auditPicInfo(picAuditVo);
    }

    @ApiOperation(value = "实物图片(上架下架)")
    @RequestMapping(value = "/picInfo/put", method = RequestMethod.POST)
    public Object operatorPicStatus(@RequestBody PicPutVo picPutVo) {
        return pictureService.operatorPicStatus(picPutVo);
    }

    @ApiOperation(value = "新增/修改图片信息")
    @RequestMapping(value = "/picInfo",method = RequestMethod.POST)
    public Object operatorPicInfo(@RequestBody PicInfoDetailVo picInfoDetailVo){return pictureService.addPicInfo(picInfoDetailVo);
    }


    @ApiOperation(value = "根据ID删除图片信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "picID", required = true, value = "picID", defaultValue = "X123"),
    })
    @RequestMapping(value = "/picInfo/{picID}", method = RequestMethod.DELETE)
    public Object deletePicInfo(@PathVariable Long picID) {
        return pictureService.deleteByPrimaryKey(picID);
    }


    @ApiOperation(value = "查看图片信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "picID", required = true, value = "picID", defaultValue = "a123"),
    })
    @RequestMapping(value = "/picInfo/{picID}", method = RequestMethod.GET)
    public Object getByPicInfo(@PathVariable Long picID) {
        return pictureService.selectByPrimaryKey(picID);
    }


    @ApiOperation(value = "检查图片编号")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "pictureno", required = true, value = "pictureno", defaultValue = "a123"),
    })
    @RequestMapping(value = "/picInfo/check/{pictureno}", method = RequestMethod.GET)
    public Object checkPictureNo(@PathVariable String pictureno) {
        return pictureService.checkPictureNo(pictureno);
    }



    @ApiOperation(value = "用户收藏图片")
    @RequestMapping(value = "/picEnshrine",method = RequestMethod.POST)
    public Object addPicEnshrine(@RequestBody PicEnshrineVo picEnshrineVo){return pictureService.userPicEnshrine(picEnshrineVo);
    }

    @ApiOperation(value = "用户取消收藏图片")
    @RequestMapping(value = "/picEnshrine",method = RequestMethod.PUT)
    public Object cancelPicEnshrine(@RequestBody PicEnshrineVo picEnshrineVo){
        return pictureService.userCancelEnshrine(picEnshrineVo);
    }


    @ApiOperation(value = "图片列表分页")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "pageSize", required = true, value = "分页大小", defaultValue = "5"),
            @ApiImplicitParam(paramType = "path", name = "pageNum", required = true, value = "当前页", defaultValue = "1"),
    })
    @RequestMapping(value = "/picInfo/list/{pageNum}/{pageSize}", method = RequestMethod.GET)
    public Object queryListPicInfo(@PathVariable Integer pageNum,@PathVariable Integer pageSize) {
        return pictureService.queryListPicInfo(pageNum,pageSize);
    }

    @ApiOperation(value = "图片列表(出入库使用)")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "pageSize", required = true, value = "分页大小", defaultValue = "5"),
            @ApiImplicitParam(paramType = "path", name = "pageNum", required = true, value = "当前页", defaultValue = "1"),
    })
    @RequestMapping(value = "/picInfo/lists/{pageNum}/{pageSize}", method = RequestMethod.GET)
    public Object queryListPicInfos(@PathVariable Integer pageNum,@PathVariable Integer pageSize) {
        return pictureService.queryListPicInfos(pageNum,pageSize);
    }


    @ApiOperation(value = "条件查询图片")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "pageSize", required = true, value = "分页大小", defaultValue = "5"),
            @ApiImplicitParam(paramType = "path", name = "pageNum", required = true, value = "当前页", defaultValue = "1"),
    })
    @RequestMapping(value = "/picInfo/lists/{pageNum}/{pageSize}", method = RequestMethod.POST)
    public Object queryListPicInfo(@RequestBody QueryPicInfoDto queryPicInfoDto, @PathVariable Integer pageNum, @PathVariable Integer pageSize) {
        return pictureService.queryListPicInfo(queryPicInfoDto,pageNum,pageSize);
    }


    @ApiOperation(value = "用户ID查询图片收藏")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "pageSize", required = true, value = "分页大小", defaultValue = "5"),
            @ApiImplicitParam(paramType = "path", name = "pageNum", required = true, value = "当前页", defaultValue = "1"),
    })
    @RequestMapping(value = "/picEnshrine/list/{userID}/{pageNum}/{pageSize}", method = RequestMethod.GET)
    public Object selectUserPicEnshrine(@PathVariable Long userID,@PathVariable Integer pageNum,@PathVariable Integer pageSize) {
        return pictureService.selectUserPicEnshrine(userID,pageNum,pageSize);
    }


    @ApiOperation(value = "用户ID查询图片")
    @RequestMapping(value = "/picInfo/listByUser/{pageNum}/{pageSize}", method = RequestMethod.POST)
    public Object selectUserPicList(@RequestBody PicInfoByUserVo picInfoByUserVo,@PathVariable Integer pageNum,@PathVariable Integer pageSize) {
        return pictureService.queryListPicInfoByUser(picInfoByUserVo,pageNum,pageSize);
    }


    @ApiOperation(value = "根据ID删除收藏")
    @RequestMapping(value = "/picEnshrine/{enshrineid}", method = RequestMethod.DELETE)
    public Object delUserPicEnshrine(@PathVariable Long enshrineid) {
        return pictureService.delUserPicEnshrine(enshrineid);
    }

    @ApiOperation(value = "检查用户收藏图片")
    @RequestMapping(value = "/picEnshrine/check/{pictureid}/{userid}", method = RequestMethod.GET)
    public Object checkUserEnshrine(@PathVariable Long pictureid,@PathVariable Long userid) {
        return pictureService.checkUserEnshrine(pictureid,userid);
    }


    @ApiOperation(value = "新增系统标签")
    @RequestMapping(value = "/picSysTag",method = RequestMethod.POST)
    public Object addPicTags(@RequestBody PicSysTagsVo picSysTagsVo){
        return picTagsService.addPicSysTag(picSysTagsVo);
    }

    @ApiOperation(value = "更新系统标签")
    @RequestMapping(value = "/picSysTag",method = RequestMethod.PUT)
    public Object updatePicTags(@RequestBody PicSysTagsVo picSysTagsVo){
        return picTagsService.updateByPicLabel(picSysTagsVo);
    }

    @ApiOperation(value = "ID查询系统标签")
    @RequestMapping(value = "/picSysTag/{tagid}", method = RequestMethod.GET)
    public Object getByPicSysTag(@PathVariable Long tagid) {
        return picTagsService.selectByPrimaryKey(tagid);
    }

    @ApiOperation(value = "ID删除系统标签")
    @RequestMapping(value = "/picSysTag/{tagid}", method = RequestMethod.DELETE)
    public Object deletePicSysTag(@PathVariable Long tagid) {
        return picTagsService.deleteByPrimaryKey(tagid);
    }


    @ApiOperation(value = "系统标签组列表")
    @RequestMapping(value = "/picSysTag/list", method = RequestMethod.POST)
    public Object selectAllTags(@RequestBody QueryPicTagDto queryPicTagDto) {
        return picTagsService.selectAllTags(queryPicTagDto);
    }

    @ApiOperation(value = "查询所有系统标签信息")
    @RequestMapping(value = "/picSysTag/lists/{pageNum}/{pageSize}", method = RequestMethod.GET)
    public Object selectListAllTags(@PathVariable Integer pageNum,@PathVariable Integer pageSize) {
        return picTagsService.selectListTags();
    }

    @ApiOperation(value = "给图片打系统标签")
    @RequestMapping(value = "/picSysTags",method = RequestMethod.POST)
    public Object addPicSysTags(@RequestBody PicTagsVo picTagsVo){
        return picTagsService.addPicSysTags(picTagsVo);
    }


    @ApiOperation(value = "批量删除图片里系统标签")
    @RequestMapping(value = "/picInfo/deltag", method = RequestMethod.POST)
    public Object deleteByTagItemid(@RequestBody PicTagsVo picTagsVo) {
        return picTagsService.deleteByTagItemid(picTagsVo);
    }

    @ApiOperation(value = "系统标签组查询图片列表")
    @RequestMapping(value = "/picInfo/taglist/{pageNum}/{pageSize}", method = RequestMethod.POST)
    public Object queryListPicInfoByTag(@RequestBody PicTagVo picTagVo, @PathVariable Integer pageNum,@PathVariable Integer pageSize) {
        return pictureService.queryListPicInfoByTag(picTagVo);
    }


    @ApiOperation(value = "图片下载统计")
    @RequestMapping(value = "/downfile/{picid}",method = RequestMethod.GET)
    public Object downloadFile(@PathVariable Long picid) throws Exception {
      return pictureService.downfile(picid);
    }


    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "codes", required = true,
                    value = "类型编码(年龄:LJ_TYPE,皮肤:PF_TYPE,性格:XG_TYPE,款式:KS_TYPE,套系:TX_TYPE,职业:ZY_TYPE)", defaultValue = "LJ_TYPE"),
    })
    @ApiOperation(value = "查询类型数据")
    @RequestMapping(value = "/picBaseDict", method = RequestMethod.POST)
    public Object selectListDict(@RequestBody List<String> codes) {
        return picDictService.selectListDict(codes);
    }


    @ApiOperation(value = "查询系列数据")
    @RequestMapping(value = "/series/query/{id}", method = RequestMethod.GET)
    public Object selectByParentId(@PathVariable Long id) {
        return picSeriesService.selectByParentId(id);
    }


    @ApiOperation(value = "退出系统")
    @RequestMapping(value = "/logout", method = RequestMethod.GET)
    public Object logout() {
        Map<String,Object> map= SystemContext.getToken();
        String userid=map.get("userId")!=null?map.get("userId").toString():"";
        boolean res=false;
        if (!userid.equals("")){
            res=redisTemplate.delete(userid);
        }
        return res;
    }


    @ApiOperation(value = "图片来源关联")
    @RequestMapping(value = "/picRelation",method = RequestMethod.POST)
    public Object pictureRelation(@RequestBody PicRelationVo picRelationVo){
        return pictureService.pictureRelation(picRelationVo);
    }

}
